package com.iknow.xml;

import android.text.Spannable;
import android.text.SpannableStringBuilder;
import com.iknow.ui.model.IKPageAdapter;
import com.iknow.util.SpannableUtil;
import com.iknow.util.enums.IKTagEnum;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class IKValuePageData
{
  private static final long serialVersionUID = 1L;
  private IKPageAdapter adapter = null;
  private List<IKValuePageData_Item> cacheList = null;
  private Spannable cacheText = null;

  public IKValuePageData()
  {
    this.cacheList = new ArrayList();
  }

  private void addTextDataItem()
  {
    if (this.cacheText == null);
    while (true)
    {
      return;
      SpannableStringBuilder localSpannableStringBuilder = new SpannableStringBuilder(this.cacheText.subSequence(0, this.cacheText.length() - 1));
      IKValuePageData_Item localIKValuePageData_Item = new IKValuePageData_Item();
      localIKValuePageData_Item.type = IKTagEnum.TEXT;
      localIKValuePageData_Item.data.put("text", localSpannableStringBuilder);
      toDataItem(localIKValuePageData_Item);
      this.cacheText = null;
    }
  }

  private void toDataItem(IKValuePageData_Item paramIKValuePageData_Item)
  {
    synchronized (this.cacheList)
    {
      if (this.adapter == null)
        this.cacheList.add(paramIKValuePageData_Item);
      return;
    }
  }

  public void addDataItem(IKValuePageData_Item paramIKValuePageData_Item)
  {
    if ((paramIKValuePageData_Item.type == IKTagEnum.PHASE) || (paramIKValuePageData_Item.type == IKTagEnum.STYLEPHASE) || (paramIKValuePageData_Item.type == IKTagEnum.TEXT) || (paramIKValuePageData_Item.type == IKTagEnum.A) || (paramIKValuePageData_Item.type == IKTagEnum.BR))
    {
      Spannable localSpannable = (Spannable)paramIKValuePageData_Item.data.get("text");
      this.cacheText = SpannableUtil.mergeSpanna(this.cacheText, localSpannable);
      if (this.cacheText != null)
      {
        String str = this.cacheText.toString();
        if ((str != null) && (str.length() > 100) && (str.endsWith("\n")))
          addTextDataItem();
      }
    }
    while (true)
    {
      return;
      addTextDataItem();
      toDataItem(paramIKValuePageData_Item);
    }
  }

  public void endData()
  {
    addTextDataItem();
  }

  // ERROR //
  public void setAdapter(IKPageAdapter paramIKPageAdapter)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 26	com/iknow/xml/IKValuePageData:cacheList	Ljava/util/List;
    //   4: astore_2
    //   5: aload_2
    //   6: monitorenter
    //   7: aload_0
    //   8: aload_1
    //   9: putfield 24	com/iknow/xml/IKValuePageData:adapter	Lcom/iknow/ui/model/IKPageAdapter;
    //   12: aload_0
    //   13: getfield 26	com/iknow/xml/IKValuePageData:cacheList	Ljava/util/List;
    //   16: invokeinterface 124 1 0
    //   21: astore 4
    //   23: aload 4
    //   25: invokeinterface 130 1 0
    //   30: ifne +15 -> 45
    //   33: aload_0
    //   34: getfield 26	com/iknow/xml/IKValuePageData:cacheList	Ljava/util/List;
    //   37: invokeinterface 133 1 0
    //   42: aload_2
    //   43: monitorexit
    //   44: return
    //   45: aload 4
    //   47: invokeinterface 137 1 0
    //   52: checkcast 6	com/iknow/xml/IKValuePageData$IKValuePageData_Item
    //   55: pop
    //   56: goto -33 -> 23
    //   59: astore_3
    //   60: aload_2
    //   61: monitorexit
    //   62: aload_3
    //   63: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   7	62	59	finally
  }

  public void stop()
  {
    if (this.cacheList != null)
    {
      this.cacheList.clear();
      this.cacheList = null;
      this.adapter = null;
      this.cacheText = null;
    }
  }

  public static class IKValuePageData_Item
  {
    public Map<String, Object> data;
    public IKTagEnum type = null;

    public IKValuePageData_Item()
    {
      this.data = null;
      this.data = new HashMap();
    }

    public IKValuePageData_Item clone()
      throws CloneNotSupportedException
    {
      IKValuePageData_Item localIKValuePageData_Item = new IKValuePageData_Item();
      localIKValuePageData_Item.type = this.type;
      localIKValuePageData_Item.data = new HashMap(this.data);
      return localIKValuePageData_Item;
    }
  }
}